﻿{extend name="public:base" /}

{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">标题</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="title" placeholder="请输入标题" value="{$info.title}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">素材文件</label>
                                <div class="col-sm-3">
                                    <input type="file" id="upload_file" accept=".mp3" style="display: none">
                                    <input type="hidden" name="file_path" id="file" value="{$info['file_path']|default=''}"/>
                                    <div class="btn btn-primary btn-lg" id="up_file_btn">上传文件</div>
                                </div>
                            </div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row music-box" style="display: none">
                                <label class="col-sm-1 col-form-label"></label>
                                <div class="col-sm-3">
                                    <audio id="audio" controls style="max-height: 200px" src="{$info['file_path']}"></audio>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}


{block name="js"}
<script>
    var file_path = '{$info.file_path}';

    if(file_path){
        $('.music-box').show();
    }

    $('#up_file_btn').click(function () {
        $('#upload_file').trigger('click')
        $('#upload_file').change(function () {
            var pic = $(this)[0].files[0];
            var formData = new FormData();
            var url = "/Upload/UploadFile/uploadFile";
            var name = pic['name'];

            formData.append('download', pic);
            formData.append('name', name);

            $.ajax({
                url: url,
                type: "post",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.status == 1) {
                        clearFile('upload_file');

                        var path = data.data.path;
                        $('.music-box').show();
                        $('#audio').attr('src', path);
                        $('#file').val(path);
                    } else {
                        layer.msg(data.info);
                    }
                }
            })
        })
    })
</script>{/block}